From: Florian Müllner Date: Mon, 16 Dec 2024 13:33:00 +0000 (+0100) Subject: status/a11y: Simplify switch setup X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~177^2^2~8 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=a73e44c0ba6067df685ab1f4faa7b236a8af6cba;p=gnome-shell.git status/a11y: Simplify switch setup Almost all switches represent boolean settings, which means we can use bindings instead of fiddling with signal handlers. As menu items have a `:sensitive` property, this also deals with handling keys' writability. Part-of: (cherry picked from commit 6029380267879eb6491a9f429afa22b380da4fa2) --- diff --git a/js/ui/status/accessibility.js b/js/ui/status/accessibility.js index b36c64868..5e6c447f3 100644 --- a/js/ui/status/accessibility.js +++ b/js/ui/status/accessibility.js @@ -118,17 +118,12 @@ class ATIndicator extends PanelMenu.Button { } _buildItem(string, schema, key) { - let settings = new Gio.Settings({schema_id: schema}); - let widget = this._buildItemExtended(string, - settings.get_boolean(key), - settings.is_writable(key), - enabled => settings.set_boolean(key, enabled)); + const settings = new Gio.Settings({schema_id: schema}); + const widget = new PopupMenu.PopupSwitchMenuItem(string, false); + settings.bind(key, widget, 'state', Gio.SettingsBindFlags.DEFAULT); - settings.connect(`changed::${key}`, () => { - widget.setToggleState(settings.get_boolean(key)); - - this._queueSyncMenuVisibility(); - }); + widget.connect('toggled', + () => this._queueSyncMenuVisibility()); return widget; }